﻿using System; 
using System.Data.SqlClient;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using T.FAS.Runtime.Metadata.Entity.DataModel;
using T.ServiceComponent.DAC.Service;
using T.FAS.Runtime.Base.Dao;

namespace T.FAS.Runtime.DataModel.Dao
{
    public class ColumnPermissionViewDao : DaoService<ColumnPermissionView>
    { 
        public override string TableName => "v_fas_column_permission";
        public override string IDColumnName => "ID";
        public string ForeignColumn => "DoId";

        public override List<string> ExceptColumnName {get;} = new List<string>
        {

        };

        public ColumnPermissionViewDao() : base()
        {
            DBName = "TFAS";
        }

        /// <summary>
        /// 根据列权限sql获取指定do的所有授权列
        /// </summary>
        /// <param name="doIds"></param>
        /// <returns></returns>
        public List<ColumnPermissionView> GetColumnPermissionViews(List<string> doIds, string authSQL)
        { 
            var result = new List<ColumnPermissionView>();
            if (doIds == null)
            {
                return result;
            }
            var ids = string.Join("','", doIds);
            var dt = base.GetByFilter($"{ForeignColumn} in ('{ids}') and ({authSQL})");
            result = DaoUtil.ConvertToEntity<ColumnPermissionView>(dt, this.ExceptColumnName); 
            return result;
        }

        /// <summary>
        /// 根据列权限sql获取指定do的所有授权列
        /// </summary>
        /// <param name="authSQL"></param>
        /// <returns></returns>
        public List<ColumnPermissionView> GetAllColumnPermissionViews(string authSQL)
        {
            var result = new List<ColumnPermissionView>();
            if (string.IsNullOrEmpty(authSQL))
            {
                return result;
            }
            var dt = base.GetByFilter(authSQL);
            result = DaoUtil.ConvertToEntity<ColumnPermissionView>(dt, this.ExceptColumnName);
            return result;
        }
    }
}
